import json
import re

def process_json_2(i):

    # 读取 JSON 文件
    file_path = fr"D:\subtitle\goods\walmart_goods_{i}.json"
    # file_path = r"D:\subtitle\goods\walmart_goods_25.json"

    with open(file_path, "r", encoding="utf-8") as f:
        data = f.read()

    data = re.sub(r'\[Selling\s+points\]', '[Selling Points]', data)
    data = re.sub(r'\[Target\s+groups\]', '[Target Groups]', data)
    data = re.sub(r'\[Usage\s+scenarios\]', '[Usage Scenarios]', data)

    data = re.sub(r'Selling\s+[Pp]oints', '[Selling Points]', data)
    data = re.sub(r'Target\s+[Gg]roups', '[Target Groups]', data)
    data = re.sub(r'Usage\s+[Ss]cenarios', '[Usage Scenarios]', data)

    data = data.replace("[[", "[").replace("]]", "]")

    # 使用正则表达式替换连续两个空格为 ""
    data = re.sub(r' {2}', '', data)

    json_data = json.loads(data)

    # 重新写入 JSON 文件
    with open(file_path, "w", encoding="utf-8") as f:
        json.dump(json_data, f, ensure_ascii=False, indent=4)

    print(f"处理完成{i}。")


if __name__ == "__main__":
    for i in range(1,26):
        process_json_2(i)